include config.mk

LIBRENDER =  librender.a
LIBDIX =     libdix.a
LIBOS =      libos.a
LIBMI =      libmi.a
LIBXEXT =    libxext.a
LIBXEXTMOD = libXextmod.a
LIBXTRAP =   libxtrap.a
LIBKDRIVE =  libkdrive.a
LIBLINUX =   liblinux.a
LIBFB =      libfb.a
LIBSHADOW =  libshadow.a
LIBLAYER =   liblayer.a
LIBRANDR =   librandr.a
LIBRECORD =  librecord.a
LIBXVESA =   libxvesa.a
LIBXFBDEV =  libxfbdev.a
LIBXNEST =   libxnest.a

XVESA =  Xvesa
XFBDEV = Xfbdev
XNEST =  Xnest

LIBOSSRC =\
	os/WaitFor.c\
	os/access.c\
	os/connection.c\
	os/io.c\
	os/osinit.c\
	os/utils.c\
	os/auth.c\
	os/mitauth.c\
	os/secauth.c\
	os/xdmcp.c\
	os/decompress.c\
	os/transport.c\
	os/oscolor.c

LIBXEXTSRC =\
	Xext/bigreq.c\
	Xext/mbuf.c\
	Xext/saver.c\
	Xext/xf86dga2.c\
	Xext/xtest.c\
	Xext/cup.c\
	Xext/mbufpx.c\
	Xext/xf86dga.c\
	Xext/xvdisp.c\
	Xext/mitmisc.c\
	Xext/shm.c\
	Xext/xf86misc.c\
	Xext/xvmain.c\
	Xext/dpmsstubs.c\
	Xext/sleepuntil.c\
	Xext/xf86vmode.c\
	Xext/xvmc.c\
	Xext/EVI.c\
	Xext/sync.c\
	Xext/xprint.c\
	Xext/xvmod.c\
	Xext/fontcache.c\
	Xext/xcmisc.c\
	Xext/xtest1dd.c\
	Xext/mbufbf.c\
	Xext/sampleEVI.c\
	Xext/xf86bigfont.c\
	Xext/xtest1di.c

LIBXEXTMODSRC =\
	Xext/extmod/bigreq.c\
	Xext/extmod/EVI.c\
	Xext/extmod/sampleEVI.c\
	Xext/extmod/sync.c\
	Xext/extmod/xf86dga.c\
	Xext/extmod/xvdisp.c\
	Xext/extmod/xvmod.c\
	Xext/extmod/cup.c\
	Xext/extmod/mitmisc.c\
	Xext/extmod/saver.c\
	Xext/extmod/xcmisc.c\
	Xext/extmod/xf86misc.c\
	Xext/extmod/xvmain.c\
	Xext/extmod/modinit.c\
	Xext/extmod/xf86dga2.c\
	Xext/extmod/xf86vmode.c\
	Xext/extmod/xvmc.c

LIBDIXSRC =     $(wildcard dix/*.c)
LIBRENDERSRC =  $(wildcard render/*.c)
LIBMISRC =      $(wildcard mi/*.c)
LIBXTRAPSRC =   $(wildcard XTrap/*.c)
LIBKDRIVESRC =  $(wildcard hw/kdrive/*.c)
LIBLINUXSRC =   $(wildcard hw/kdrive/linux/*.c)
LIBFBSRC =      $(wildcard fb/*.c)
LIBSHADOWSRC =  $(wildcard miext/shadow/*.c)
LIBLAYERSRC =   $(wildcard miext/layer/*.c)
LIBRANDRSRC =   $(wildcard randr/*.c)
LIBRECORDSRC =  $(wildcard record/*.c)
LIBXVESASRC =   $(wildcard hw/kdrive/vesa/*.c)
LIBXFBDEVSRC =  $(wildcard hw/kdrive/fbdev/*.c)
LIBXNESTSRC =   $(wildcard hw/xnest/*.c)

ifeq ($(SHAPE),-DSHAPE)
LIBXEXTSRC +=    Xext/shape.c
LIBXEXTMODSRC += Xext/extmod/shape.c
endif

ifeq ($(DPMS),-DDPMSExtension)                                                 
LIBXEXTSRC +=    Xext/dpms.c
LIBXEXTMODSRC += Xext/extmod/dpms.c
endif

ifeq ($(PANORAMIX),-DPANORAMIX) 
LIBXEXTSRC +=\
	Xext/panoramiX.c\
	Xext/panoramiXSwap.c\
	Xext/panoramiXprocs.c
endif

LIB = $(LIBXFBDEV) $(LIBRENDER) $(LIBDIX) $(LIBOS) $(LIBMI) $(LIBXEXT)\
      $(LIBXEXTMOD) $(LIBXTRAP) $(LIBKDRIVE) $(LIBLINUX) $(LIBFB)\
      $(LIBSHADOW) $(LIBLAYER) $(LIBRANDR) $(LIBRECORD) $(LIBXNEST)

LIBRENDEROBJ =  $(LIBRENDERSRC:.c=.o)
LIBDIXOBJ =     $(LIBDIXSRC:.c=.o)
LIBOSOBJ =      $(LIBOSSRC:.c=.o)
LIBMIOBJ =      $(LIBMISRC:.c=.o)
LIBXEXTOBJ =    $(LIBXEXTSRC:.c=.o)
LIBXEXTMODOBJ = $(LIBXEXTMODSRC:.c=.o)
LIBXTRAPOBJ =   $(LIBXTRAPSRC:.c=.o)
LIBKDRIVEOBJ =  $(LIBKDRIVESRC:.c=.o)
LIBLINUXOBJ =   $(LIBLINUXSRC:.c=.o)
LIBFBOBJ =      $(LIBFBSRC:.c=.o)
LIBSHADOWOBJ =  $(LIBSHADOWSRC:.c=.o)
LIBLAYEROBJ =   $(LIBLAYERSRC:.c=.o)
LIBRANDROBJ =   $(LIBRANDRSRC:.c=.o)
LIBRECORDOBJ =  $(LIBRECORDSRC:.c=.o)
LIBXVESAOBJ =   $(LIBXVESASRC:.c=.o)
LIBXFBDEVOBJ =  $(LIBXFBDEVSRC:.c=.o)
LIBXNESTOBJ =   $(LIBXNESTSRC:.c=.o)

OBJ = $(LIBRENDEROBJ) $(LIBDIXOBJ) $(LIBOSOBJ) $(LIBMIOBJ) $(LIBXEXTOBJ)\
      $(LIBXEXTMODOBJ) $(LIBXTRAPOBJ) $(LIBKDRIVEOBJ) $(LIBLINUXOBJ)\
      $(LIBFBOBJ) $(LIBSHADOWOBJ) $(LIBLAYEROBJ) $(LIBRANDROBJ)\
      $(LIBRECORDOBJ) $(LIBXFBDEVOBJ) $(LIBXNESTOBJ)

BIN = $(XFBDEV) $(XNEST)

all: $(LIB) $(XFBDEV) $(XNEST)

.c.o:
	$(CC) $(DEFS) $(INC) $(CFLAGS) -c $< -o $@

$(LIBRENDER): $(LIBRENDEROBJ)
	$(AR) rcs $@ $?
$(LIBDIX): $(LIBDIXOBJ)
	$(AR) rcs $@ $?
$(LIBOS): $(LIBOSOBJ)
	$(AR) rcs $@ $?
$(LIBMI): $(LIBMIOBJ)
	$(AR) rcs $@ $?
$(LIBXEXT): $(LIBXEXTOBJ)
	$(AR) rcs $@ $?
$(LIBXEXTMOD): $(LIBXEXTMODOBJ)
	$(AR) rcs $@ $?
$(LIBXTRAP): $(LIBXTRAPOBJ)
	$(AR) rcs $@ $?
$(LIBKDRIVE): $(LIBKDRIVEOBJ)
	$(AR) rcs $@ $?
$(LIBLINUX): $(LIBLINUXOBJ)
	$(AR) rcs $@ $?
$(LIBFB): $(LIBFBOBJ)
	$(AR) rcs $@ $?
$(LIBSHADOW): $(LIBSHADOWOBJ)
	$(AR) rcs $@ $?
$(LIBLAYER): $(LIBLAYEROBJ)
	$(AR) rcs $@ $?
$(LIBRANDR): $(LIBRANDROBJ)
	$(AR) rcs $@ $?
$(LIBRECORD): $(LIBRECORDOBJ)
	$(AR) rcs $@ $?
$(LIBXVESA): $(LIBXVESAOBJ)
	$(AR) rcs $@ $?
$(LIBXFBDEV): $(LIBXFBDEVOBJ)
	$(AR) rcs $@ $?
$(LIBXNEST): $(LIBXNESTOBJ)
	$(AR) rcs $@ $?

$(XFBDEV): $(LIB)
	$(CC) $(LDFLAGS) -o $@ $(LIBDIX) $(LIBKDRIVE) $(LIBOS) $(LIBXFBDEV) \
	$(LIBLAYER) $(LIBLINUX) $(LIBSHADOW) $(LIBFB) \
	$(LIBMI) $(LIBXEXT) $(LIBXEXTMOD) $(LIBXTRAP) $(LIBRANDR) \
	$(LIBRENDER) $(LIBRECORD) $(LIBS)

$(XNEST): $(LIB)
	$(CC) $(LDFLAGS) -o $@ $(LIBDIX) $(LIBOS) $(LIBXNEST) $(LIBMI) \
	$(LIBRANDR) $(LIBXEXT) $(LIBXTRAP) $(LIBRECORD) $(LIBRENDER) $(LIBS)

install: $(BIN)
	mkdir -p $(DESTDIR)/$(PREFIX)/bin
	cp -f $(XFBDEV) $(DESTDIR)/$(PREFIX)/bin/$(XFBDEV)
	cp -f $(XNEST) $(DESTDIR)/$(PREFIX)/bin/$(XNEST)
	chmod 0755 $(DESTDIR)/$(PREFIX)/bin/$(XFBDEV)

uninstall:
	rm -f $(DESTDIR)/$(PREFIX)/bin/$(XFBDEV)
	rm -f $(DESTDIR)/$(PREFIX)/bin/$(XNEST)

clean:
	rm -f $(OBJ) $(LIB) $(BIN)

.PHONY:
	clean install uninstall all